﻿using System;
using System.Collections.Generic;
using System.Linq;
using LostLib.Algorithms;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Tests.LostLib
{
    
    
    /// <summary>
    ///This is a test class for DiffTest and is intended
    ///to contain all DiffTest Unit Tests
    ///</summary>
	[TestClass()]
	public class DiffTest
	{


		private TestContext testContextInstance;

		/// <summary>
		///Gets or sets the test context which provides
		///information about and functionality for the current test run.
		///</summary>
		public TestContext TestContext
		{
			get
			{
				return testContextInstance;
			}
			set
			{
				testContextInstance = value;
			}
		}

		#region Additional test attributes
		// 
		//You can use the following additional attributes as you write your tests:
		//
		//Use ClassInitialize to run code before running the first test in the class
		//[ClassInitialize()]
		//public static void MyClassInitialize(TestContext testContext)
		//{
		//}
		//
		//Use ClassCleanup to run code after all tests in a class have run
		//[ClassCleanup()]
		//public static void MyClassCleanup()
		//{
		//}
		//
		//Use TestInitialize to run code before running each test
		//[TestInitialize()]
		//public void MyTestInitialize()
		//{
		//}
		//
		//Use TestCleanup to run code after each test has run
		//[TestCleanup()]
		//public void MyTestCleanup()
		//{
		//}
		//
		#endregion


		/// <summary>
		///A test for LongestCommonSubsequence
		///</summary>
		public void LongestCommonSubsequenceTestHelper<T>()
		{
			string a = "abcMFC"; // TODO: Initialize to an appropriate value
			string b = "cbaMFC"; // TODO: Initialize to an appropriate value
			var actual = new string(Diff<char>.LongestCommonSubsequence(a.ToCharArray(), b.ToCharArray()).ToArray());
			var excepted = "cMFC";
			Assert.AreEqual(actual, excepted);
		}

		[TestMethod()]
		public void LongestCommonSubsequenceTest()
		{
			LongestCommonSubsequenceTestHelper<GenericParameterHelper>();
		}

		[TestMethod()]
		public void GetDiffTest()
		{
			string a = "abcMFC";
			string b = "cbaMFC";
			var diff = Diff<char>.GetDiff(a.ToCharArray(), b.ToCharArray()).ToArray();

			Assert.AreEqual(diff.Length, 2);

			Assert.AreEqual(diff[0].Count, 2);
			Assert.AreEqual(diff[0].IsInsert, false);

			Assert.AreEqual(diff[1].IsInsert, true);
			Assert.AreEqual(new string(diff[1].Data.ToArray()), "ba");
		}
	}
}
